
/**
 * 抽象事件
 */
abstract class AbstractEvent {


    // 消息发送工厂
    public msgFactory(content: string, type:string, uinfo: any) {
        var _html = '';
        if ('mine' == type) {
            _html += '<li class="laykefu-chat-mine">';
        } else {
            _html += '<li>';
        }
        _html += '<div class="laykefu-chat-user">';
        _html += '<img src="' + uinfo.avatar + '">';
        if ('mine' == type) {
            _html += '<cite><i>' + this.getDate() + '</i>' + uinfo.username + '</cite>';
        } else {
            _html += '<cite>' + uinfo.name + '<i>' +  this.getDate() + '</i></cite>';
        }
        _html += '</div><div class="laykefu-chat-text">' + (content) + '</div>';
        _html += '</li>';

        return _html;
    }

    // 获取日期
    public getDate(): string {
        var d = new Date(new Date());

        return d.getFullYear() + '-' +  this.digit(d.getMonth() + 1) + '-' +  this.digit(d.getDate())
            + ' ' + this.digit(d.getHours()) + ':' +  this.digit(d.getMinutes()) + ':' +  this.digit(d.getSeconds());
    }
    //补齐数位
    public digit(num: number){
        return num < 10 ? '0' + (num | 0) : num;
    }
}

export default AbstractEvent;